/*
  @author dmj1161859184@126.com 2018-08-11 21:19
  @version 1.0
  @since 1.0
*/
angular.module("myApp", [])
    .controller("myCtr", function ($scope) {
        $scope.todos = [
            {name: '吃饭', isChecked: false},
            {name: '睡觉', isChecked: false},
            {name: '打豆豆', isChecked: false}
        ];
        $scope.add = function () {
            if (!$scope.newTodo) {
                return;
            }
            var obj = {
                name: $scope.newTodo,
                isChecked: false
            };
            $scope.todos.unshift(obj);
            $scope.newTodo = '';
        };
        // $scope.del = function () {
        //     $scope.todos.forEach(function (item,index) {
        //         if (item.isChecked) {
        //             $scope.todos.splice(index,1);
        //             $scope.del();//递归，调用自己
        //         }
        //     })
        // }
        $scope.del = function () {
            var oldTodoList = $scope.todos;
            $scope.todos = [];
            oldTodoList.forEach(function (item, index) {
                if (!item.isChecked) {
                    $scope.todos.push(item);
                }
            });
            $scope.todos = oldTodoList;
        }
    });